package com.threeti.jiayusms.domain.service.communicationtime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.threeti.jiayusms.domain.model.CommunicationTime;
import com.threeti.jiayusms.framework.util.DynaSearchCriteria;
import com.threeti.jiayusms.framework.util.PagedListHandler;
import com.threeti.jiayusms.infrastructure.communicationtime.CommunicationTimeDao;
import com.threeti.jiayusms.interfaces.TimeTemplateDynaCriteriaDto;

@Service
@Transactional(readOnly=true)
public class CommunicationTimeQueryServiceImpl implements CommunicationTimeQueryService {
	@Autowired
	private CommunicationTimeDao dao;

	@Override
	public CommunicationTime findCommunicationTimeBy(Long timeId) {
		return dao.loadBy(timeId, true);
	}
	
	@Override
	public CommunicationTime findCommunicationTimeBy(String timeNo) {
		return dao.loadBy(timeNo);
	}
	
	@Override
	public PagedListHandler<CommunicationTime> findAllTimeTemplatesByPage(int currentPageIndex, int startingIndex) {
    return dao.findAllTimeTemplatesByPage(currentPageIndex, startingIndex);
	}
	
	@Override
	public PagedListHandler<CommunicationTime> findTimeTemplatesByPage(DynaSearchCriteria dynaSearchCriteria, int currentPageIndex, int startingIndex) {
		TimeTemplateDynaCriteriaDto dynaCriteria = (TimeTemplateDynaCriteriaDto)dynaSearchCriteria;
		String templateKeywords = dynaCriteria.getTemplateKeywords();
		if (!StringUtils.hasText(templateKeywords)) {//无条件查询
			return dao.findAllTimeTemplatesByPage(currentPageIndex, startingIndex);
		}
    return dao.findTimeTemplatesByPage(dynaSearchCriteria, currentPageIndex, startingIndex);
	}
}
